package com.zyb.warehouse.mapper;

import com.zyb.warehouse.dto.Page;
import com.zyb.warehouse.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Description:商品表持久层接口
 */
@Mapper
public interface ProductMapper {

    /**
     * 查询商品总记录数
     *
     * @param product
     * @return
     */
    Integer selectProductTotal(Product product);

    /**
     * 分页查询商品
     *
     * @param page
     * @param product
     * @return
     */
    List<Product> pageProduct(@Param("page") Page page, @Param("product") Product product);

    /**
     * 添加商品
     *
     * @param product
     * @return
     */
    Integer insertProduct(Product product);

    /**
     * 查询是否存在重复编号的产品
     *
     * @param productNum
     * @return
     */
    @Select("select * from product where product_num=#{productNum}")
    Product selectProductByNum(String productNum);

    /**
     * 根据商品Id查询商品
     *
     * @param productId
     * @return
     */
    @Select("select * from product where product_id=#{productId}")
    Product selectProductById(Integer productId);

    /**
     * 修改商品
     *
     * @param product
     * @return
     */
    @Update("update product set up_down_state=#{upDownState}," +
            "update_by = #{updateBy},update_time = now() where product_id=#{productId}")
    Integer updateProductSate(Product product);

    /**
     * 修改商品
     *
     * @param product
     * @return
     */
    Integer updateProduct(Product product);

    /**
     * 删除商品
     *
     * @param productIds
     * @return
     */
    Integer deleteProduct(List<Integer> productIds);

    /**
     * 修改商品库存
     *
     * @param productId
     * @param number
     * @return
     */
    @Update("update product set product_invent=product_invent+#{number} where product_id=#{productId}")
    Integer updateProductInventById(Integer productId, Integer number);
}
